package com.vcc.service.impl;

import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.vcc.data.entity.UsdtRecharge;
import com.vcc.data.mapper.UsdtRechargeMapper;
import com.vcc.service.service.UsdtRechargeService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class UsdtRechargeServiceImpl extends ServiceImpl<UsdtRechargeMapper, UsdtRecharge> implements UsdtRechargeService {
    @Override
    public List<UsdtRecharge> listByStartTimeAndEndTime(Date startDate, Date endDate, Integer status) {
        return queryChain()
                .eq(UsdtRecharge::getStatus, status)
                .ge(UsdtRecharge::getRequestDate, startDate)
                .le(UsdtRecharge::getRequestDate, endDate)
                .list();
    }

    @Override
    public List<UsdtRecharge> listByStatus(Integer status) {
        return queryChain()
                .eq(UsdtRecharge::getStatus, status)
                .list();
    }

    @Override
    public Boolean updateStatusAndRemark(Long id, Integer status, String remark) {
        return updateChain()
                .set(UsdtRecharge::getStatus, status)
                .set(UsdtRecharge::getRemark, remark)
                .eq(UsdtRecharge::getId, id)
                .update();
    }

    @Override
    public Boolean setFormAddress(Long id, Integer status, String fromAddress, String hash, Long block, Long blockTs,String info) {
        return updateChain()
                .set(UsdtRecharge::getStatus, status)
                .set(UsdtRecharge::getRemittanceAddress, fromAddress)
                .set(UsdtRecharge::getRemittanceTxId, hash)
                .set(UsdtRecharge::getBlockHeight, String.valueOf(block))
                .set(UsdtRecharge::getConfirmDate, new Date(blockTs))
                .set(UsdtRecharge::getExpandText, info)
                .set(UsdtRecharge::getRemark, "自动确认")
                .eq(UsdtRecharge::getId, id)
                .update();
    }

    @Override
    public Boolean existsByTransactionId(String transactionId) {
        return queryChain()
                .eq(UsdtRecharge::getRemittanceTxId, transactionId)
                .exists();
    }
}
